﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using nspLable.Using;
using UserInfo;
using Base;
public partial class _Default :BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!BasePage.Config.isClosed)
        {
            Response.Write(Base.BasePage.Config.ClosedMessage);
            return;
        }
        //if (!IsPostBack)
        //{
        string WSbody = new Principal().GetTemplate("Index");
        Response.Write(WSbody);
        //}
        string UserName = "";
        string Password = "";
        if (Request.Form["UserName"] != "" && Request.Form["UserName"] != null && Request.Form["Password"] != "" && Request.Form["Password"] != null)
        {
            UserName = Request.Form["UserName"];
            Password = Request.Form["Password"];
            string Md5Pawd = Common.Encryption(Password);
            UserLogin(UserName, Md5Pawd); 
        }
    }

    public void UserLogin(string UserName, string Password)
    {
        RUserInfo User = new RUserInfo();
        DataSet tableset = User.GetDataTable(UserName, Password);
        //判断是否存在该会员
        if (tableset.Tables[0].Rows.Count != 0)
        {
            if (tableset.Tables[0].Rows[0]["Verify"].ToString().Equals("False"))   //
            {
                Response.Redirect("Error.aspx?err=3");
            }
            else
            {
                string strIP = Base.GetRequest.GetIP();
                int UserID = int.Parse(tableset.Tables[0].Rows[0]["UserID"].ToString());
                GetRequest.SetCookie("LoginName", tableset.Tables[0].Rows[0]["LoginName"].ToString());
                GetRequest.SetCookie("UserID", tableset.Tables[0].Rows[0]["UserID"].ToString());
                GetRequest.SetCookie("GradeID", tableset.Tables[0].Rows[0]["GradeID"].ToString());
                GetRequest.SetCookie("CompanyName", tableset.Tables[0].Rows[0]["CompanyName"].ToString());
                this.Response.Redirect("~/member/Index.aspx");
            }
        }
        else
        {
            Response.Write("<script> window.open(\"Login/login.aspx?err=1\",\"_blank\") </script>  ");
        }
    }
}
